package cn.schoolwow.util.module.check.instance.flow;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

import java.util.ArrayList;
import java.util.List;

public class CheckInstanceNotRepeatFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        List list = (List) flowContext.getData("list");
        String message = (String) flowContext.checkData("message");

        if(null==list){
            return;
        }
        List repeatList = new ArrayList<>();
        for(Object instance:list){
            if(repeatList.contains(instance)){
                throw new IllegalArgumentException(message+"包含重复值!重复值:["+instance+"]");
            }
            repeatList.add(instance);
        }
    }

    @Override
    public String name() {
        return "实例-检查列表值是否有重复值";
    }
}
